import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.util.ArrayList;

import javax.swing.JApplet;
import javax.swing.JFrame;


public class TSPDrawer extends JApplet{
	double[][] pos;
	int[] solution;
	int scale;
	int length;
	public TSPDrawer(double[][] pos, int[] solution, int scale, int length){
		this.pos = pos;
		this.solution = solution;
		this.scale = scale;
		this.length = length;
		
		JFrame frame = new JFrame("TSPDrawer");
		frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        });
		frame.getContentPane().add("Center", this);
		frame.pack();
        frame.setSize(new Dimension(500,500));
        frame.setVisible(true);
	}
	public void paint(Graphics graphics) {
		Graphics2D g = (Graphics2D) graphics;
		int node_size = 20;
		
		for(int i=0;i<length;i++){
			g.setPaint(Color.BLACK);
			g.draw(new Ellipse2D.Double(pos[solution[i]][0]*scale-node_size/2, pos[solution[i]][1]*scale-node_size/2, node_size, node_size));
			g.draw(new Line2D.Double(pos[solution[i]][0]*scale, 
									 pos[solution[i]][1]*scale, 
									 pos[solution[(i+1) % length]][0]*scale, 
									 pos[solution[(i+1) % length]][1]*scale));
			
			g.setPaint(Color.RED);
			g.drawString(""+solution[i], (int)pos[solution[i]][0]*scale+15, (int)pos[solution[i]][1]*scale+5);
		}
	}
}
